package com.yanqingshan.platform.module.sys.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yanqingshan.platform.module.auth.model.domain.UserTokenInfo;
import com.yanqingshan.platform.module.sys.model.domain.SysUser;
import com.yanqingshan.platform.module.sys.model.vo.SysUserInfoRespVO;
import com.yanqingshan.platform.module.sys.model.vo.SysUserReqVO;
import com.yanqingshan.platform.module.sys.model.vo.SysUserRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * 功能描述: 用户类型转化
 *
 * @author yanqs
 * @since 2023-05-13
 */
@Mapper
public interface SysUserConvert {

    SysUserConvert INSTANCE = Mappers.getMapper(SysUserConvert.class);

    /**
     * 用户信息转化
     *
     * @param param 请求参数
     * @return 用户实体
     */
    default SysUser infoConvert(SysUserReqVO param) {
        SysUser sysUser = new SysUser();
        sysUser.setId(param.getId());
        sysUser.setNickName(param.getNickName());
        sysUser.setAvatar(param.getAvatar());
        sysUser.setSex(param.getSex());
        sysUser.setPhone(param.getPhone());
        sysUser.setEmail(param.getEmail());
        return sysUser;
    }


    SysUserInfoRespVO convert(SysUser user);

    @Mappings({
            @Mapping(source = "id", target = "userId"),
            @Mapping(source = "nickName", target = "userName")
    })
    UserTokenInfo.UserInfo convert1(SysUser user);

    Page<SysUserRespVO> convert2(Page<SysUser> page);
}
